﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GameSchool.Models;

namespace GameSchool.Controllers
{
    public class SupervisorController : Controller
    {
		//GameSchoolRepository repository = new GameSchoolRepository();
        IGameSchoolRepository repository = null;

        public SupervisorController()
        {
            repository = new GameSchoolRepository();
        }

        public SupervisorController(IGameSchoolRepository rep)
        {
            repository = rep;
        }
        //
        // GET: /Supervisor/
        #region Views
		
		// Displays a list of courses and number of students and teachers in 
		// each course               
		public ActionResult SupervisorHome() // Ólöf
        {
            SupervisorPartialViewModel vm = new SupervisorPartialViewModel();
            var numOfStudents = 0;
            var numOfTeachers = 0;
			var item = repository.GetCourses();
            foreach (var course in item)
            {
                var students = repository.GetStudentsInCourse(course);
                numOfStudents = students.Count();
                course.numStudents = numOfStudents;
                var teachers = repository.GetTeachersInCourse(course);
                numOfTeachers = teachers.Count();
                course.numTeachers = numOfTeachers;
            }
			vm.courses = item.ToList();
			return View(vm);
        }

        #endregion
    }
}
